-- Copyright (c) 2011, bkil.hu
-- This program is free software and can be distributed under the terms of
-- the GNU General Public License v2,
-- see COPYING for detailed licensing terms.
-- created on 2010-07-10 19:58
-- http://www.metnet.hu/?m=fc_race&sub=results
-- I wanted to know who is the most dependable forecaster.

import System.IO(hGetContents,stdin)
import Data.Maybe(catMaybes)
import Data.List(maximumBy)

csv2matrix = map (lines . map tab2nl) . lines where
 tab2nl '\t' = '\n'
 tab2nl x = x	

fixMetnet (a:b:xs) = ab : fixMetnet xs where
 (a1,a2) = splitAt 12 a
 ab = a1 ++ b ++ a2
fixMetnet xs = xs

maybeRead s =
 case reads s of 
  [(x, "")] -> Just x
  _         -> Nothing

process f = r where
 table = fixMetnet $ csv2matrix f
 eachMin = [
  let
   strs = take 9 t
-- reverse $ drop 2 $ reverse t
   nums = map (maybeRead::String->Maybe Float) strs
  in (read id::Int,minimum nums) |
  (id:name:t) <- table ]
 r = maximumBy (\(_,x)(_,y)->compare x y) eachMin

main = do
 hGetContents stdin >>= print . process

